package com.park.web.controller;

import com.park.web.base.baseOperation.BaseController;
import com.park.web.core.wrapper.WrapMapper;
import com.park.web.core.wrapper.Wrapper;
import com.park.web.model.domain.basSystemManage;
import com.park.web.model.domain.basSystemResource;
import com.park.web.model.dto.basSystemResourceDto;
import com.park.web.service.basSystemResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(value = "WEB - BasSystemResourceController", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = "basSystemResource", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class BasSystemResourceController extends BaseController {

    @Autowired
    basSystemResourceService ibasSystemResourceService;

    @GetMapping("/MenuList/{userId}")
    @ApiOperation(value = "用户ID", notes = "用户ID")
    public Wrapper queryMenuList(@PathVariable("userId") String userId) {
        List<basSystemManage> list = ibasSystemResourceService.getMenuTree(userId);
        return WrapMapper.okWithoutMessage(list);
    }

    @PostMapping("/findUserBt/{recourceCode}")
    @ApiOperation(value = "查询子菜单", notes = "查询子菜单")
    public Wrapper findUserBt(@PathVariable("recourceCode") String recourceCode) {
        var list = ibasSystemResourceService.selectByParentCode(recourceCode);
        return WrapMapper.okWithoutMessage(list);
    }


    @GetMapping("/resourcesTree")
    @ApiOperation(value = "查询系统资源结构树", notes = "查询系统资源结构树")
    public Wrapper resourceTree() {
        try {
            var list = ibasSystemResourceService.queryResourceTree();
            return WrapMapper.okWithoutMessage(list);
        } catch (Exception ex) {
            return WrapMapper.error();
        }
    }

    @GetMapping("/resourcesList")
    @ApiOperation(value = "通过模块id查询子节点资源", notes = "通过模块id查询子节点资源")
    public Wrapper resourcesList(basSystemResourceDto entity){
        var list = ibasSystemResourceService.queryResourcesList(entity);
        return WrapMapper.okWithoutMessage(list);
    }
}
